<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>点击变色</title>
    <style>
        .active {
            color: yellow;
            background-color: red;
        }
    </style>
</head>
<body>
<div id="app">
    <ul>
        <li v-for="(item, index) in movies" v-bind:id="index" v-on:click="liClicked(index)"
            v-bind:class="{active: index === currentIndex}">{{ item }}
        </li>
    </ul>
</div>

<script type="module">
    import {createApp, reactive, ref} from "../../../../../js/vue.esm-browser.js";

    const app = createApp({
        setup() {
            let movies = reactive(["霸王别姬", "河边的错误", "三体", "教父"])
            let currentIndex = ref(null)

            function liClicked(index) {
                this.currentIndex = index
            }

            return {
                movies,
                currentIndex,
                liClicked,
            }
        }
    })

    app.mount("#app")
</script>
</body>
</html>